package com.sparrow.resource.convert.impl;

import org.springframework.core.convert.converter.Converter;

/**
 * 字符串转int数组
 * 数据模板 1,2,3,4,5
 */
public class IntArrayConverter implements Converter<String, int[]> {

    @Override
    public int[] convert(String source) {
        if (source == null || source.trim().isEmpty()) {
            return new int[0];
        }

        String[] split = source.split(",");
        int[] array = new int[split.length];

        for (int i = 0; i < split.length; i++) {
            array[i] = Integer.parseInt(split[i].trim());
        }

        return array;
    }
}

